"""Verify project setup without running the full application."""
import sys
import os

def verify_structure():
    """Verify project structure."""
    required_dirs = [
        'app',
        'app/models',
        'app/services',
        'app/routes',
        'app/tasks',
        'tests'
    ]
    
    required_files = [
        'config.py',
        'run.py',
        'requirements.txt',
        '.env.example',
        'app/__init__.py',
        'app/models/__init__.py',
        'app/services/__init__.py',
        'app/routes/__init__.py',
        'tests/conftest.py'
    ]
    
    print("Verifying project structure...")
    
    # Check directories
    for dir_path in required_dirs:
        if os.path.isdir(dir_path):
            print(f"✓ Directory exists: {dir_path}")
        else:
            print(f"✗ Missing directory: {dir_path}")
            return False
    
    # Check files
    for file_path in required_files:
        if os.path.isfile(file_path):
            print(f"✓ File exists: {file_path}")
        else:
            print(f"✗ Missing file: {file_path}")
            return False
    
    print("\n✓ All required files and directories are present!")
    return True


def verify_imports():
    """Verify basic Python syntax."""
    print("\nVerifying Python syntax...")
    
    try:
        # Just check if files can be compiled
        import py_compile
        
        files_to_check = [
            'config.py',
            'run.py',
            'app/__init__.py'
        ]
        
        for file_path in files_to_check:
            py_compile.compile(file_path, doraise=True)
            print(f"✓ {file_path} syntax is valid")
        
        print("✓ All Python files have valid syntax")
        return True
    except Exception as e:
        print(f"✗ Syntax error: {e}")
        return False


if __name__ == '__main__':
    print("=" * 60)
    print("步语 (Buyu) Backend Setup Verification")
    print("=" * 60)
    
    structure_ok = verify_structure()
    imports_ok = verify_imports()
    
    if structure_ok and imports_ok:
        print("\n" + "=" * 60)
        print("✓ Setup verification PASSED!")
        print("=" * 60)
        print("\nNext steps:")
        print("1. Install dependencies: pip install -r requirements.txt")
        print("2. Copy .env.example to .env and configure")
        print("3. Run the application: python run.py")
        sys.exit(0)
    else:
        print("\n" + "=" * 60)
        print("✗ Setup verification FAILED!")
        print("=" * 60)
        sys.exit(1)
